<?php

!defined('IN_FENGTOP') && exit('Access Denied');
 
class control extends base{

	function control(& $get,& $post){
		$this->base( & $get,& $post);
		$this->load('user');
	}

	function dologin(){
		if(isset($_COOKIE['FT_username'])){
			header("HTTP/1.1 301 Moved Permanently");
			header("location: http://magicube.ws/magicube/");
		}
		
		if(isset($this->post['ssoLogin'])){
			$data=$this->post;
			$res = $_ENV['FTcenter']->HTTP_Post(SSO_URL.'/ssoLogin.php', $data, $_COOKIE);
			$arr = json_decode($res, TRUE);
//print_r($arr);
			$this->FTsetcookie('username', $arr['username']);
			$this->FTsetcookie('ticket'  , $arr['ticket']  );
//print_r($_COOKIE);
			header("HTTP/1.1 301 Moved Permanently");
			header("location: http://magicube.ws/magicube/");
		}else{
			$this->view->display('login.tpl');
		}
	}
	
	function docode(){
		if(isset($this->setting['checkcode'])){
			$codecase = $this->setting['checkcode'];
		}else{
			$codecase = 0;
		}
		$code=util::random(4,$codecase);
		if(function_exists("imagecreate")){
			$_ENV['user']->save_code(strtolower($code),$this->user['username']);
			
//echo $this->user['username']; echo $code;exit;
			util::makecode($code);
		}else{
			$_ENV['user']->save_code('abcd',$this->user['username']);
			header('location:style/default/vdcode.jpg');
		}
	}

}
?>